<template>
  <a-drawer
    :title="title"
    :width="width"
    placement="right"
    :closable="false"
    @close="close"
    :visible="visible">
  
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-form-item label="采购方总部编码，国家电网：sgcc" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'purchaserHqCode', validatorRules.purchaserHqCode]" placeholder="请输入采购方总部编码，国家电网：sgcc"></a-input>
        </a-form-item>
        <a-form-item label="销售订单号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'soNo', validatorRules.soNo]" placeholder="请输入销售订单号"></a-input>
        </a-form-item>
        <a-form-item label="供应商编码，即厂商编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'supplierCode', validatorRules.supplierCode]" placeholder="请输入供应商编码，即厂商编码"></a-input>
        </a-form-item>
        <a-form-item label="采购方编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'buyerCode', validatorRules.buyerCode]" placeholder="请输入采购方编码"></a-input>
        </a-form-item>
        <a-form-item label="采购方公司省份，不带省字" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'buyerProvince', validatorRules.buyerProvince]" placeholder="请输入采购方公司省份，不带省字"></a-input>
        </a-form-item>
        <a-form-item label="销售订单与采购订单的关联方式 1.关联到采购订单。 2.关联到采购订单行项目。0.无关联" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'soRelType', validatorRules.soRelType]" placeholder="请输入销售订单与采购订单的关联方式 1.关联到采购订单。 2.关联到采购订单行项目。0.无关联"></a-input>
        </a-form-item>
        <a-form-item label="品类编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'categoryCode', validatorRules.categoryCode]" placeholder="请输入品类编码"></a-input>
        </a-form-item>
        <a-form-item label="种类编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'subclassCode', validatorRules.subclassCode]" placeholder="请输入种类编码"></a-input>
        </a-form-item>
        <a-form-item label="销售订单状态" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'soStatus', validatorRules.soStatus]" placeholder="请输入销售订单状态"></a-input>
        </a-form-item>
        <a-form-item label="数据来源" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'dataSource', validatorRules.dataSource]" placeholder="请输入数据来源"></a-input>
        </a-form-item>
        <a-form-item label="来源数据创建时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'dataSourceCreateTime', validatorRules.dataSourceCreateTime]" placeholder="请输入来源数据创建时间"></a-input>
        </a-form-item>
        <a-form-item label="删除标志 1.是，0.否" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'isDeleted', validatorRules.isDeleted]" placeholder="请输入删除标志 1.是，0.否"></a-input>
        </a-form-item>
        <a-form-item label="供应商销售订单号，来自供应商" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'supplierSoNo', validatorRules.supplierSoNo]" placeholder="请输入供应商销售订单号，来自供应商"></a-input>
        </a-form-item>
        <a-form-item label="销售订单行项目号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'soItemNo', validatorRules.soItemNo]" placeholder="请输入销售订单行项目号"></a-input>
        </a-form-item>
        <a-form-item label="销售订单行项目与采购订单的关联方式 1.关联到采购订单。 2.关联到采购订单行项目 。0.无关联。" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'supplierSoRelType', validatorRules.supplierSoRelType]" placeholder="请输入销售订单行项目与采购订单的关联方式 1.关联到采购订单。 2.关联到采购订单行项目 。0.无关联。"></a-input>
        </a-form-item>
        <a-form-item label="物资编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'productCode', validatorRules.productCode]" placeholder="请输入物资编码"></a-input>
        </a-form-item>
        <a-form-item label="物资名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'productName', validatorRules.productName]" placeholder="请输入物资名称"></a-input>
        </a-form-item>
        <a-form-item label="物资单位" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'productUnit', validatorRules.productUnit]" placeholder="请输入物资单位"></a-input>
        </a-form-item>
        <a-form-item label="物资数量" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'productAmount', validatorRules.productAmount]" placeholder="请输入物资数量"></a-input>
        </a-form-item>
        <a-form-item label="物资id分组编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'productIdGrpNo', validatorRules.productIdGrpNo]" placeholder="请输入物资id分组编号"></a-input>
        </a-form-item>
        <a-form-item label="采购订单厂家计划交货日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'planDeliveryDate', validatorRules.planDeliveryDate]" placeholder="请输入采购订单厂家计划交货日期"></a-input>
        </a-form-item>
        <a-form-item label="采购订单厂家发货地点" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'planDeliveryPlace', validatorRules.planDeliveryPlace]" placeholder="请输入采购订单厂家发货地点"></a-input>
        </a-form-item>
        <a-form-item label="采购订单厂家发货地点描述" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'planDeliveryPlaceDesc', validatorRules.planDeliveryPlaceDesc]" placeholder="请输入采购订单厂家发货地点描述"></a-input>
        </a-form-item>
        <a-form-item label="1：未读（默认状态）
0：成功；" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'ioflag', validatorRules.ioflag]" placeholder="请输入1：未读（默认状态）
0：成功；"></a-input>
        </a-form-item>
        <a-form-item label="错误信息，接口同步返回消息" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'message', validatorRules.message]" placeholder="请输入错误信息，接口同步返回消息"></a-input>
        </a-form-item>
        <a-form-item label="本条数据值新增/更新，0：新增，1：更新" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'status', validatorRules.status]" placeholder="请输入本条数据值新增/更新，0：新增，1：更新"></a-input>
        </a-form-item>
        <a-form-item label="全局交易流水号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'transno', validatorRules.transno]" placeholder="请输入全局交易流水号"></a-input>
        </a-form-item>
        <a-form-item label="orderId" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'orderId', validatorRules.orderId]" placeholder="请输入orderId" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="采购订单编号或者采购订单行项目号，SORELTYPE是1或2时必填" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'eipPoNo', validatorRules.eipPoNo]" placeholder="请输入采购订单编号或者采购订单行项目号，SORELTYPE是1或2时必填"></a-input>
        </a-form-item>
        <a-form-item label="数据拥有方" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'ownerId', validatorRules.ownerId]" placeholder="请输入数据拥有方"></a-input>
        </a-form-item>
        <a-form-item label="数据可见方" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'openId', validatorRules.openId]" placeholder="请输入数据可见方"></a-input>
        </a-form-item>
        <a-form-item label="推送时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择推送时间" v-decorator="[ 'pushTime', validatorRules.pushTime]" :trigger-change="true" style="width: 100%"/>
        </a-form-item>
        
      </a-form>
    </a-spin>
    <a-button type="primary" @click="handleOk">确定</a-button>
    <a-button type="primary" @click="handleCancel">取消</a-button>
  </a-drawer>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import JDate from '@/components/jeecg/JDate'  
  
  export default {
    name: "ZxjEipXsddModal",
    components: { 
      JDate,
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title:"操作",
        width:800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        validatorRules:{
        purchaserHqCode:{rules: [{ required: true, message: '请输入采购方总部编码，国家电网：sgcc!' }]},
        soNo:{rules: [{ required: true, message: '请输入销售订单号!' }]},
        supplierCode:{rules: [{ required: true, message: '请输入供应商编码，即厂商编码!' }]},
        buyerCode:{rules: [{ required: true, message: '请输入采购方编码!' }]},
        buyerProvince:{rules: [{ required: true, message: '请输入采购方公司省份，不带省字!' }]},
        soRelType:{},
        categoryCode:{rules: [{ required: true, message: '请输入品类编码!' }]},
        subclassCode:{rules: [{ required: true, message: '请输入种类编码!' }]},
        soStatus:{rules: [{ required: true, message: '请输入销售订单状态!' }]},
        dataSource:{rules: [{ required: true, message: '请输入数据来源!' }]},
        dataSourceCreateTime:{rules: [{ required: true, message: '请输入来源数据创建时间!' }]},
        isDeleted:{rules: [{ required: true, message: '请输入删除标志 1.是，0.否!' }]},
        supplierSoNo:{rules: [{ required: true, message: '请输入供应商销售订单号，来自供应商!' }]},
        soItemNo:{rules: [{ required: true, message: '请输入销售订单行项目号!' }]},
        supplierSoRelType:{},
        productCode:{rules: [{ required: true, message: '请输入物资编码!' }]},
        productName:{rules: [{ required: true, message: '请输入物资名称!' }]},
        productUnit:{rules: [{ required: true, message: '请输入物资单位!' }]},
        productAmount:{rules: [{ required: true, message: '请输入物资数量!' }]},
        productIdGrpNo:{},
        planDeliveryDate:{rules: [{ required: true, message: '请输入采购订单厂家计划交货日期!' }]},
        planDeliveryPlace:{rules: [{ required: true, message: '请输入采购订单厂家发货地点!' }]},
        planDeliveryPlaceDesc:{},
        ioflag:{rules: [{ required: true, message: '请输入1：未读（默认状态）0：成功；!' }]},
        message:{},
        status:{},
        transno:{},
        orderId:{rules: [{ required: true, message: '请输入orderId!' }]},
        eipPoNo:{},
        ownerId:{rules: [{ required: true, message: '请输入数据拥有方!' }]},
        openId:{rules: [{ required: true, message: '请输入数据可见方!' }]},
        pushTime:{},
        },
        url: {
          add: "/zxjEipXsdd/zxjEipXsdd/add",
          edit: "/zxjEipXsdd/zxjEipXsdd/edit",
        }
     
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'purchaserHqCode','soNo','supplierCode','buyerCode','buyerProvince','soRelType','categoryCode','subclassCode','soStatus','dataSource','dataSourceCreateTime','isDeleted','supplierSoNo','soItemNo','supplierSoRelType','productCode','productName','productUnit','productAmount','productIdGrpNo','planDeliveryDate','planDeliveryPlace','planDeliveryPlaceDesc','ioflag','message','status','transno','orderId','eipPoNo','ownerId','openId','pushTime'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }
         
        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'purchaserHqCode','soNo','supplierCode','buyerCode','buyerProvince','soRelType','categoryCode','subclassCode','soStatus','dataSource','dataSourceCreateTime','isDeleted','supplierSoNo','soItemNo','supplierSoRelType','productCode','productName','productUnit','productAmount','productIdGrpNo','planDeliveryDate','planDeliveryPlace','planDeliveryPlaceDesc','ioflag','message','status','transno','orderId','eipPoNo','ownerId','openId','pushTime'))
      }
      
    }
  }
</script>

<style lang="less" scoped>
/** Button按钮间距 */
  .ant-btn {
    margin-left: 30px;
    margin-bottom: 30px;
    float: right;
  }
</style>